function tomock(res, obj) {
	var responseText = JSON.parse(res);
	var hot = document.getElementById(obj);
	for (var i = 0; i < responseText.list.length; i++) {
		var div = document.createElement('div');
		div.classList.add('hot-box');
		div.innerHTML = '<img src=' + responseText.list[i].src + '>\
		<p>' + responseText.list[i].title +
			'</p>\
		<p class="space-between">\<span>￥' + responseText.list[i].value + '</span>' +
			'<img class="buy" src=./img/buy.svg></p>'
		hot.appendChild(div)
	}
}
app.mockhot('/hot', function(res) {
	tomock(res, 'hot-main')
})
app.mockhot('/hot', function(res) {
	tomock(res, 'special-main')
})

app.mockhot('/menu', function(res) {
	var responseText = JSON.parse(res);
	var menu = document.getElementById('menu-ul');
	for (var i = 0; i < responseText.img.length; i++) {
		var li = document.createElement('li');
		var im = document.createElement('img');
		var p = document.createElement('p');
		im.src = responseText.img[i];
		p.textContent = responseText.title[i];
		menu.appendChild(li)
		li.appendChild(im)
		li.appendChild(p)
	}
})
app.mockhot('/banner', function(res) {
	var responseText = JSON.parse(res);
	var menu = document.getElementById('menu-ul');
	var box = document.getElementById('banner-box');
	var li = box.getElementsByTagName('li');
	for (var i = 0; i < responseText.src.length; i++) {
		li[i].style.background = 'url(' + responseText.src[i] + ') no-repeat center center';
	}
})

window.onload = function() {
	app.banner('home-banner', 3000);
	app.pubu(4, '/cloth','<img class="buy" src=./img/buy.svg>')
}

function backtop() {
	var btop = document.getElementById('backtop');
	var timer = null;

	function scrollTop() {
		cancelAnimationFrame(timer);
		timer = requestAnimationFrame(function sTop() {
			var top = document.body.scrollTop || document.documentElement.scrollTop;
			if (top > 0) {
				document.body.scrollTop = document.documentElement.scrollTop = top - 100;
				timer = requestAnimationFrame(sTop);
			} else {
				cancelAnimationFrame(timer);
			}
		});
	}
	btop.addEventListener('touchend', scrollTop, false);
}
backtop()

function giveclass() {
	var ul = document.getElementById('menu-ul');
	var li = ul.getElementsByTagName('li');
	setTimeout(function() {
		li[7].addEventListener('touchend', function() {
			plus.webview.open('list.html', 'q', {}, 'pop-in', 600)
		})
	}, 1000)
}
giveclass()

document.addEventListener('plusready', function() {
	var jump = document.getElementById('home-form');
	var classify = document.getElementById('classify');
	var buyt = document.getElementById('buyt');
	classify.addEventListener('touchend', function() {
		plus.webview.open('classify.html', 'q', {}, 'pop-in', 600)
	});
	buyt.addEventListener('touchend', function() {
		plus.webview.open('shop-cart.html', 'q', {}, 'pop-in', 600)
	})
	jump.addEventListener('touchend', function() {
		plus.webview.open('search.html', 'q', {}, 'pop-in', 600)
	})
});
